package com.bls.cate.ui.activity.home;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.bls.cate.R;
import com.bls.cate.bean.HomeBean;
import com.bls.cate.mvp.BasePresenterImpl;
import com.bls.cate.ui.fragment.alllist.AllListFragment;
import com.bls.cate.ui.fragment.flyleaf.FlyleafFragment;
import com.bls.cate.ui.fragment.me.MeFragment;

import java.util.ArrayList;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class HomePresenter extends BasePresenterImpl<HomeContract.View> implements HomeContract.Presenter {

    @Override
    public ArrayList<HomeBean.BottomBarBean> getBottomBarBean() {
        String[] strings = new String[]{"FLYLEAF", "ALL", "ME"};
        int[] selectImg = new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};
        int[] unSelectImg = new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};
        ArrayList<HomeBean.BottomBarBean> bottomBarBeans = new ArrayList<>();
        HomeBean.BottomBarBean bottomBarBean;
        for (int i = 0, j = strings.length; i < j; i++) {
            bottomBarBean = new HomeBean.BottomBarBean(selectImg[i], unSelectImg[i], strings[i], false);
            bottomBarBeans.add(bottomBarBean);
        }
        bottomBarBeans.get(0).setSelect(true);
        return bottomBarBeans;
    }

    @Override
    public Fragment[] getFragments() {
        return new Fragment[]{FlyleafFragment.newInstance("", ""), AllListFragment.newInstance("", ""), MeFragment.newInstance("", "")};
    }

    public void switchFragment(int index, int bottomBarOldClickPosition, FragmentManager fragmentManager, Fragment[] fragments) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        if (bottomBarOldClickPosition == index) return;
        if (!fragments[index].isAdded())
            transaction.add(R.id.fl_content, fragments[index]);
        if (bottomBarOldClickPosition != -1 && fragments[bottomBarOldClickPosition].isAdded()) {
            transaction.hide(fragments[bottomBarOldClickPosition]);
        }
        transaction.show(fragments[index]);
        transaction.commit();
        mView.setNewBottomBarOldClickPosition(index);
    }
}
